package com.project.app.server.estates;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.SecurityUtils;
import com.project.server.domain.estates.TServiceRecord;
import com.project.server.service.estates.ITServiceRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小程序服务记录
 */
@RestController
@RequestMapping("/app/server/serviceRecord")
public class ATServiceRecordController extends BaseController {

    @Resource
    private ITServiceRecordService tServiceRecordService;

    /**
     * 查询服务记录列表
     */
    //@PreAuthorize("@ss.hasPermi('server:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TServiceRecord tServiceRecord) {
        startPage();
        List<TServiceRecord> list = tServiceRecordService.selectTServiceRecordList(tServiceRecord);
        return getDataTable(list);
    }

//    /**
//     * 服务人员获取服务记录详细信息
//     */
//   // @PreAuthorize("@ss.hasPermi('server:record:query')")
//    @GetMapping(value = {"/{openId}", "/{serviceId}"})
//    public AjaxResult getInfoById(@PathVariable("serviceId") Long serviceId) {
//        return AjaxResult.success(tServiceRecordService.selectTServiceRecordById(serviceId));
//    }

    /**
     * 用户获取服务记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('server:record:query')")
    @GetMapping(value = "/{openId}")
    public AjaxResult getInfo(@PathVariable("openId") String openId) {
        return AjaxResult.success(tServiceRecordService.selectTServiceRecordByOpenId(openId));
    }

    /**
     * 新增服务记录
     */
    @Log(title = "服务记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TServiceRecord tServiceRecord) {
        return toAjax(tServiceRecordService.insertTServiceRecord(tServiceRecord));
    }

    /**
     * 用户修改服务记录
     */
    //@PreAuthorize("@ss.hasPermi('server:record:edit')")
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TServiceRecord tServiceRecord) {
        tServiceRecord.setUpdateBy(SecurityUtils.getUsername());
//        return toAjax(tServiceRecordService.updateTServiceRecordByUserId(tServiceRecord));
        return null;
    }

    /**
     * 服务人员修改服务记录
     */
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping("/orderTaking")
    public AjaxResult orderTaking(@Validated @RequestBody TServiceRecord tServiceRecord) {
       // tServiceRecord.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tServiceRecordService.updateTServiceRecordByServerId(tServiceRecord));
    }

    /**
     * 修改服务记录完成状态
     */
   // @PreAuthorize("@ss.hasPermi('server:record:edit')")
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@Validated @RequestBody TServiceRecord tServiceRecord) {
        tServiceRecord.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tServiceRecordService.changeTServiceRecordStatus(tServiceRecord));
    }

    /**
     * 添加用户评价
     */
    // @PreAuthorize("@ss.hasPermi('server:record:edit')")
    @Log(title = "服务记录", businessType = BusinessType.UPDATE)
    @PutMapping("/addEvaluate")
    public AjaxResult addEvaluate(@Validated @RequestBody TServiceRecord tServiceRecord) {
        tServiceRecord.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tServiceRecordService.addServiceEvaluate(tServiceRecord));
    }

}
